package com.stock.controller;

import com.stock.domain.vo.request.LoginRequest;
import com.stock.domain.vo.response.LoginResponse;
import com.stock.domain.vo.response.Response;
import com.stock.service.UserService;
import com.stock.pojo.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

//TODO：用户功能模块
@RestController
@RequestMapping("/api")
//swagger注解 -- 模块解释
@Api(tags = "用户功能模块",value = "用户认证相关接口定义")
public class UserController {
    @Autowired
    private UserService userService;

    //根据用户名称查询用户信息
    @GetMapping("/user/{username}")
    //swagger注解 -- 方法解释
    @ApiOperation(value = "根据用户名称查询用户信息",notes = "用户信息查询",response = SysUser.class)
    //swagger注解 -- 参数解释
    @ApiImplicitParam(paramType = "path",name = "username",value = "用户名",required = true)
    public SysUser selectByUsername(@PathVariable("username") String username) {
        return userService.selectByUsername(username);
    }

    //用户登录功能
    @PostMapping("/login")
    @ApiOperation(value = "用户登录功能",notes = "用户登录",response = LoginResponse.class)
    @ApiImplicitParam(paramType = "body",name = "loginRequest",value = "登录请求参数",required = true)
    public Response<LoginResponse> login(@RequestBody LoginRequest loginRequest) {
        Response<LoginResponse> response = this.userService.login(loginRequest);
        return response;
    }

    //登录验证码接口
    @GetMapping("/captcha")
    @ApiOperation(value = "登录验证码接口",notes = "登录验证码",response = Map.class)
    public Response<Map> getCaptchaCode() {
        return userService.getCaptchaCode();
    }
}
